home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacWorld 1998 January
/
Macworld (1998-01).dmg
/
Shareware World
/
Comms & Internet
/
HTML mode 2.0 etc.
/
frontierMenu.tcl
< prev
next >
Wrap
Text File
|
1997-09-22
|
22KB
|
781 lines
## -*-Tcl-*-
# ###################################################################
# Frontier menu - tools for using Alpha as Frontier's external editor
#
# FILE: "frontierMenu.tcl"
# created: 97-04-03 22.01.22
# last update: 97-09-06 18.02.43
# Author: Johan Linde
# E-mail: <jl@theophys.kth.se>
# www: <http://bach.theophys.kth.se/~jl/Alpha.html>
#
# Version: 2.0
#
# Copyright 1997 by Johan Linde
#
# Much of the tcl code and the Frontier scripts have been written by
# Danis Georgiadis <dmg@hyper.gr>
#
# This software may be used freely, and distributed freely, as long as the
# receiver is not obligated in any way by receiving it.
#
# If you make improvements to this file, please share them!
#
# ###################################################################
##
if $startingUp {
# Use the Frontier menu icon for Alpha 6.51 and above, otherwise call the menu "Frontier".
regexp {([0-9]+\.[0-9]+)[ab]?([0-9]*)} [version] dummy __vers __beta
if {$__vers < 6.51 || $__vers == 6.51 && $__beta != ""} {
set frontierMenu Frontier
} else {
set frontierMenu "•142"
}
addMenu frontierMenu
catch {unset __vers __beta}
set frontierScriptMenu Scripts
# set frontierScriptMenu •144
return
}
proc frontierMenu {} {}
# ◊◊◊◊ Change below for new system §14 ◊◊◊◊ #
# Preferences
newModeVar Fron autoLaunch 0 1
newModeVar Fron BrowsePoints {{root root} {Websites user.websites}} 0
newModeVar Fron OpenPoints {{Websites user.websites} {Glossary user.html.glossary} {Templates user.html.templates}} 0
# ◊◊◊◊ end changing for new system §14 ◊◊◊◊ #
proc frontierBrowseMenu {} {
global FronmodeVars
set bl {}
foreach b $FronmodeVars(BrowsePoints) {
lappend bl [lindex $b 0]
}
return [list menu -n Browse -p frontierMenuProc -m [concat $bl [list "(-" "Browse at…" Add… Remove…]]]
}
proc frontierOpenMenu {} {
global FronmodeVars
set bl {}
foreach b $FronmodeVars(OpenPoints) {
lappend bl [lindex $b 0]
}
return [list menu -n Open -p frontierMenuProc -m [concat $bl [list "(-" "Open…" Add… Remove…]]]
}
# Menu definition
menu -n $frontierMenu -p frontierMenuProc -m [list \
"<U<O/FSwitch to Frontier" \
"<U<O/'View in Browser" \
"<I<O/YFrontier Shell" \
[frontierBrowseMenu] \
[frontierOpenMenu] \
"Rebuild Scripts Menu" \
Preferences…]
proc frontierMenuProc {menu item} {
global frontierMenu FronmodeVars
switch -glob $menu {
•* {
switch $item {
"Switch to Frontier" {launchForeAppl 'LAND'}
Preferences {FronmodifyFlags}
default {eval frontier[join $item ""]}
}
}
Browse {
switch $item {
"Browse at" {frontierBrowseAt}
Add {frontierAddPoint Browse}
Remove {frontierRemovePoint Browse}
default {
foreach b $FronmodeVars(BrowsePoints) {
if {[lindex $b 0] == $item} {
odbBrowse [lindex $b 1]
break
}
}
}
}
}
Open {
switch $item {
Open {frontierOpen}
Add {frontierAddPoint Open}
Remove {frontierRemovePoint Open}
default {
foreach b $FronmodeVars(OpenPoints) {
if {[lindex $b 0] == $item} {
frontierDoScript "edit (@[lindex $b 1])" front
break
}
}
}
}
}
}
}
# Called by Frontier when opening a Frontier text document in Alpha.
proc openFromFrontier {} {
global frontierWinList winModes
set name [lindex [winNames -f] 0]
set name0 [stripNameCount $name]
if {[lsearch -exact $frontierWinList $name0] < 0} {lappend frontierWinList $name0}
}
# If the current document is a Frontier document, it is updated in Frontier.
proc frontierSavePostHook {name} {
global frontierWinList
if {[lsearch -exact $frontierWinList $name] >= 0} {
launchBackAppl 'LAND'
AEBuild 'LAND' ALFA FMod "----" "“${name}”"
}
}
# ◊◊◊◊ Change below for new system §15 ◊◊◊◊ #
# Adds the above proc to the list of procs to be called after a document is saved.
if {![info exists savePostHooks] || [lsearch -exact $savePostHooks frontierSavePostHook] < 0} {
lappend savePostHooks frontierSavePostHook
}
# ◊◊◊◊ end changing for new system §15 ◊◊◊◊ #
# A list of windows opened from Frontier.
if {![info exists frontierWinList]} {set frontierWinList {}}
# Executes a script in Frontier.
proc frontierDoScript {script {front 0} {alert 1}} {
launchBackAppl 'LAND'
if {[catch {dosc -c 'LAND' -s $script} returnvalue]} {
if {$alert} {
alertnote "Frontier $returnvalue"
error "Frontier $returnvalue"
}
error $returnvalue
} elseif {$front == "front"} {
switchTo 'LAND'
}
return $returnvalue
}
# Executes one of the scripts in Frontier, which are required to use Alpha with Frontier.
proc frontierDoAlphaScript {script} {
global HOME
if {[catch {frontierDoScript $script 0 0} res]} {
alertnote "The Frontier verbs required to integrate Alpha and Frontier have not been\
properly installed. See the file 'Frontier Help.'"
edit -r -c "$HOME:Help:Frontier Help"
error $res
}
return $res
}
# ◊◊◊◊ Change below for new system §16 ◊◊◊◊ #
# Redefines closeHook
if {[info commands frontierCloseHook] == ""} {
rename closeHook frontierCloseHook
# If the window to be closed is a Frontier document, it is removed
# from Frontier's list of open external documents.
proc closeHook {name} {
global frontierWinList frontierQSWin frontierCommandHistory frontierCommandNum
# First do the normal thing.
frontierCloseHook $name
# Then do the Frontier stuff.
if {[set where [lsearch -exact $frontierWinList $name]] >= 0} {
launchBackAppl 'LAND'
AEBuild 'LAND' ALFA FCls "----" "“${name}”"
set frontierWinList [lreplace $frontierWinList $where $where]
}
if {$name == $frontierQSWin} {set frontierCommandHistory ""; set frontierCommandNum 0}
}
}
# Redefines saveasHook
if {[info commands frontierSaveasHook] == ""} {
rename saveasHook frontierSaveasHook
proc saveasHook {oldname newname} {
global frontierWinList
# First do the normal thing.
frontierSaveasHook $oldname $newname
# Modify the Frontier win list if it's a Frontier window.
# and notify Frontier about it.
if {[set where [lsearch -exact $frontierWinList $oldname]] >= 0} {
set frontierWinList [lreplace $frontierWinList $where $where $newname]
launchBackAppl 'LAND'
AEBuild 'LAND' ALFA FMod "----" "“${oldname}”" zzzz "“${newname}”"
}
}
}
# ◊◊◊◊ end changing for new system §16 ◊◊◊◊ #
# Does the same as 'View in Browser' in Frontier's web menu.
proc frontierViewinBrowser {} {
global frontierWinList
if {![llength [winNames]]} {
alertnote "No window!"
return
}
if {[lsearch $frontierWinList [set name [stripNameCount [lindex [winNames -f] 0]]]] >= 0} {
if {[winDirty]} {
if {[set ask [askyesno -c "Save '[file tail $name]'?"]] == "yes"} {
save
} elseif {$ask == "cancel"} {
return
}
}
frontierDoAlphaScript "Alpha.viewInBrowser(\"$name\")"
} else {
alertnote "Not a Frontier window."
}
}
# Open a window in Frontier
proc frontierOpen {} {
if {![catch {frontierGetAddress} addr]} {
frontierDoScript "edit (@$addr)" front
}
}
# Browse a table in Frontier
proc frontierBrowseAt {} {
if {![catch {frontierGetAddress} addr]} {
odbBrowse $addr
}
}
# Add to Browse and Open submenus
proc frontierAddPoint {type} {
global FronmodeVars modifiedModeVars
set values ""
while {1} {
set values [dialog -w 450 -h 130 -t "Add $type menu item" 30 10 290 30 \
-t "Location in database:" 10 40 160 60 -e [lindex $values 0] 165 40 440 55 \
-t "Menu text:" 78 70 160 90 -e [lindex $values 1] 165 70 440 85 \
-b OK 20 100 85 120 -b Cancel 105 100 170 120]
if {[lindex $values 3]} {return}
set addr [string trim [lindex $values 0]]
if {$addr == ""} {alertnote "Location is database must be specified."; continue}
set text [string trim [lindex $values 1]]
if {$text == ""} {alertnote "The menu item must be specified."; continue}
if {[frontierDoScript "defined($addr)"] == "true"} {
set ex 0
foreach b $FronmodeVars(${type}Points) {
if {[lindex $b 0] == $text} {alertnote "A menu item '$text' already exists."; set ex 1}
}
if {!$ex} {break}
} else {
alertnote "“$addr” is not a valid database address."
}
}
lappend FronmodeVars(${type}Points) [list $text $addr]
lappend modifiedModeVars [list ${type}Points FronmodeVars]
eval [eval frontier${type}Menu]
}
# Remove from Browse and Open submenus.
proc frontierRemovePoint {type} {
global FronmodeVars modifiedModeVars
set points {}
foreach b $FronmodeVars(${type}Points) {
lappend points [lindex $b 0]
set pointat([lindex $b 0]) [lindex $b 1]
}
if {![llength $points] || [catch {listpick -p "Select [string tolower $type] point to remove:" -l $points} points] ||
![llength $points]} {return}
set points [lindex $points 0]
if {[askyesno "'$points' points to '$pointat($points)'. Remove?"] != "yes"} {return}
set n {}
foreach b $FronmodeVars(${type}Points) {
if {[lindex $b 0] != $points} {lappend n $b}
}
set FronmodeVars(${type}Points) $n
lappend modifiedModeVars [list ${type}Points FronmodeVars]
eval [eval frontier${type}Menu]
}
proc frontierGetAddress {} {
while {1} {
if {[catch {set addr [prompt "Location in Frontier database:" ""]}]} {
error ""
} else {
set addr [string trimleft [string trim $addr] {@}]
switch [frontierDoScript "defined($addr)"] {
"true" {return $addr}
"false" {alertnote "“$addr” is not a valid database address"}
"" {error ""}
}
}
}
}
proc FronmodifyFlags {} {
global FronmodeVars modifiedModeVars
set values [dialog -w 300 -h 110 -t "Frontier Preferences" 30 10 290 30 \
-c "Launch Frontier at startup" $FronmodeVars(autoLaunch) 10 40 290 60 \
-b OK 20 80 85 100 -b Cancel 105 80 170 100]
if {[lindex $values 2]} {return}
set i -1
foreach flag [list autoLaunch] {
global $flag
incr i
set val [lindex $values $i]
if {$FronmodeVars($flag) != $val} {
set $flag $val
set FronmodeVars($flag) $val
lappend modifiedModeVars [list $flag FronmodeVars]
}
}
}
proc OdbmodifyFlags {} {
FronmodifyFlags
}
#===============================================================================
# Script menu
#
# The code to extract a Frontier menu has been written by
# Danis Georgiadis <dmg@hyper.gr>
#
#===============================================================================
proc setFrontierMenuScript {menu item scpt} {
global frontierMenuScripts
if {[regexp {&$} $item]} {
set item [string trimright $item &]
} else {
regsub -all {<[BUISEO]} $item "" item
regsub {/[a-zA-Z]} $item "" item
regsub -all {[!\^].} $item "" item
}
set key [string trimright "$menu$item" …]
set frontierMenuScripts($key) $scpt
}
proc frontierBuildScriptMenu {} {
global frontierScriptMenu FronmodeVars
set running 0
foreach p [processes] {
if {[lindex $p 1] == "LAND" } {
set running 1
}
}
if {!$running} {
if {$FronmodeVars(autoLaunch)} {
launchBackAppl 'LAND'
} else {
return
}
}
set sfina [frontierDoAlphaScript "Alpha.getMenuSource()"]
set ptext [frontierDoAlphaScript "Alpha.getDefsSource()"]
set mtext [list menu -m -n $frontierScriptMenu -p frontierScriptMenuProc $sfina]
eval $mtext
eval $ptext
insertMenu $frontierScriptMenu
}
proc frontierScriptMenuProc {menu item} {
global frontierMenuScripts frontierScriptMenu
if {$menu == $frontierScriptMenu} {set menu ""}
set key "$menu$item"
frontierDoScript $frontierMenuScripts($key)
}
proc frontierRebuildScriptsMenu {} {
global frontierMenuScripts
launchBackAppl 'LAND'
frontierDoAlphaScript "Alpha.invalMenuSources()"
catch {unset frontierMenuScripts}
frontierBuildScriptMenu
}
#===============================================================================
#
# Frontier shell
#
# Some ideas taken from Matlab mode by Stephen Merkowitz
#
#===============================================================================
set frontierQSWin "* Frontier shell *"
set frontierCommandHistory ""
set frontierCommandNum 0
proc frontierFrontierShell {} {
global frontierQSWin
if {[lsearch [winNames] $frontierQSWin] >= 0} {
bringToFront $frontierQSWin
} else {
new -n $frontierQSWin
setWinInfo -w $frontierQSWin shell 1
newMode Fron
insertText "Welcome to Alpha's Frontier shell\r«» "
}
}
proc frontierRunQuickScript {} {
global frontierCommandHistory frontierCommandNum frontierQSWin
set pos [getPos]
set ind [string first "«» " [getText [lineStart $pos] [nextLineStart [getPos]]]]
if {$ind >= 0} {
set lStart [expr [lineStart $pos]+$ind+2]
endOfLine
set scriptName [getText $lStart [getPos]]
if {[getPos] != [maxPos]} {
goto [maxPos]
insertText $scriptName
}
catch {frontierDoScript $scriptName 0 0} result
if {[string compare [lindex $frontierCommandHistory [expr [llength $frontierCommandHistory]-1]] $scriptName] != 0} {
lappend frontierCommandHistory $scriptName
if {[llength $frontierCommandHistory] > 30} {
set frontierCommandHistory [lrange $frontierCommandHistory 1 end]
}
}
set frontierCommandNum [llength $frontierCommandHistory]
if {[string length $result]} {
insertText -w $frontierQSWin "\r" $result \r "«» "
} else {
insertText -w $frontierQSWin \r "«» "
}
} else {
if {[getPos] == [maxPos]} {
insertText "«» "
} else {
carriageReturn
}
}
return
}
proc frontierPrevCommand {} {
global frontierCommandHistory frontierCommandNum
set text [getText [lineStart [getPos]] [nextLineStart [getPos]]]
if {[set ind [string first "«» " $text]] == 0} {
goto [expr [lineStart [getPos]] + $ind + 2]
} else return
incr frontierCommandNum -1
if {$frontierCommandNum < 0} {
incr frontierCommandNum
endOfLine
return
}
set text [lindex $frontierCommandHistory $frontierCommandNum]
set to [nextLineStart [getPos]]
if {[lookAt [expr $to-1]] == "\r"} {incr to -1}
replaceText [getPos] $to $text
}
proc frontierNextCommand {} {
global frontierCommandHistory frontierCommandNum
set text [getText [lineStart [getPos]] [nextLineStart [getPos]]]
if {[set ind [string first "«» " $text]] == 0} {
goto [expr [lineStart [getPos]] + $ind + 2]
} else return
incr frontierCommandNum
if {$frontierCommandNum >= [llength $frontierCommandHistory]} {
incr frontierCommandNum -1
frontierCancelLine
return
}
set text [lindex $frontierCommandHistory $frontierCommandNum]
set to [nextLineStart [getPos]]
if {[lookAt [expr $to-1]] == "\r"} {incr to -1}
replaceText [getPos] $to $text
}
proc frontierCancelLine {} {
global frontierCommandHistory frontierCommandNum
set text [getText [lineStart [getPos]] [nextLineStart [getPos]]]
if {[set ind [string first "«» " $text]] == 0} {
goto [expr [lineStart [getPos]] + $ind + 3]
} else return
set to [nextLineStart [getPos]]
deleteText [getPos] $to
set frontierCommandNum [llength $frontierCommandHistory]
}
proc frontierBol {} {
set text [getText [lineStart [getPos]] [nextLineStart [getPos]]]
if {[set ind [string first "«» " $text]] == 0} {
goto [expr [lineStart [getPos]] + $ind + 3]
} else {
goto [lineStart [getPos]]
}
}
regModeKeywords -m {«} Fron {}
bind up <z> frontierPrevCommand Fron
bind down <z> frontierNextCommand Fron
bind '\r' frontierRunQuickScript Fron
bind 'u' <z> frontierCancelLine Fron
bind left <c> frontierBol Fron
#===============================================================================
# Odb browser
#
# Written by Danis Georgiadis <dmg@hyper.gr> and modified by me to be integrated
# with the rest.
#
#===============================================================================
set odbBrowserTabLength 3
set odbBrowserTypeOffset 60
proc odbget120Spaces {} {
set spaces40 " "
return "$spaces40$spaces40$spaces40"
}
proc odbGetIndLevel {indStr} {
global odbBrowserTabLength
return [expr [string length $indStr] / $odbBrowserTabLength]
}
proc odbGetIndString {indLevel} {
global odbBrowserTabLength
return [string range [odbget120Spaces] 0 [expr [expr $indLevel * $odbBrowserTabLength] - 1]]
}
proc odbGetNextIndString {thisIndStr} {
return [odbGetIndString [expr [odbGetIndLevel $thisIndStr] + 1]]
}
proc odbBrowseGetLineParts {name type addr level} {
global odbBrowserTypeOffset
global odbBrowserTabLength
set indPadPart [odbGetIndString $level]
set namePart [string trim $name "\t "]
set typePadSize [expr $odbBrowserTypeOffset - [expr [string length $indPadPart] + [string length $name]]]
set typePadPart [string range [odbget120Spaces] 0 [expr $typePadSize - 1]]
set typePart "◊$type◊"
set addrPart "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t∞$addr∞"
set res ""
lappend res $indPadPart $namePart $typePadPart $typePart $addrPart
return $res
}
proc odbBrowseDown {} {
set curPos [getPos]
set curLineStart [lineStart $curPos]
set curLineEnd [nextLineStart $curPos]
select $curLineStart $curLineEnd
set newLineStart [nextLineStart $curLineStart]
set newLineEnd [nextLineStart $newLineStart]
if {$newLineStart < [maxPos]} {
select $newLineStart $newLineEnd
}
}
proc odbBrowseCmdDown {{option 0}} {
set curPos [getPos]
set curLineStart [lineStart $curPos]
set curLineEnd [nextLineStart $curPos]
if {[regexp {^( *).+◊tabl◊\t+∞(.+)∞} [getText $curLineStart $curLineEnd] junk ind addr]} {
if {$option} {killWindow}
odbBrowse $addr
}
}
proc odbBrowseUp {} {
set curPos [getPos]
set curLineStart [lineStart $curPos]
set curLineEnd [nextLineStart $curPos]
select $curLineStart $curLineEnd
set newLineStart [prevLineStart $curLineStart]
set newLineEnd [nextLineStart $newLineStart]
if {$newLineEnd > 0} {
select $newLineStart $newLineEnd
}
}
proc odbBrowseCmdUp {{option 0}} {
regexp {∞(.+)∞} [getText 0 [nextLineStart 0]] junk addr
if {[set point [string last "." $addr]] >= 0} {
if {$option} {killWindow}
odbBrowse [string range $addr 0 [expr $point - 1]]
}
}
proc odbBrowserAddCells {pos cells indLevel} {
set tmp ""
set colorCodes ""
set lastPos $pos
foreach cell $cells {
set cellName [lindex $cell 0]
set cellType [lindex $cell 1]
set cellAddr [lindex $cell 2]
set parts [odbBrowseGetLineParts $cellName $cellType $cellAddr $indLevel]
set indPart [lindex $parts 0]
set namePart [lindex $parts 1]
set typePartPad [lindex $parts 2]
set typePart [lindex $parts 3]
set addrPart [lindex $parts 4]
set nameStart [expr $lastPos + [string length $indPart]]
set nameEnd [expr $nameStart + [string length $namePart]]
if {$cellType == "TEXT" || $cellType == "wptx"} {
lappend colorCodes [concat $nameStart 3]
lappend colorCodes [concat $nameEnd 0]
} elseif {$cellType == "tabl"} {
lappend colorCodes [concat $nameStart 5]
lappend colorCodes [concat $nameEnd 0]
} else {
lappend colorCodes [concat $nameStart 1]
lappend colorCodes [concat $nameEnd 0]
}
set typeStart [expr $lastPos + [string length $indPart] + [string length $namePart] + [string length $typePartPad]]
set typeEnd [expr $typeStart + [string length $typePart]]
lappend colorCodes [concat $typeStart 4]
lappend colorCodes [concat $typeEnd 0]
set line ""
append line $indPart $namePart $typePartPad $typePart $addrPart "\n"
append tmp $line
set lastPos [expr $lastPos + [string length $line]]
}
select $pos $pos
setWinInfo read-only 0
insertText $tmp
foreach colorCode $colorCodes {
insertColorEscape [lindex $colorCode 0] [lindex $colorCode 1]
}
setWinInfo dirty 0
setWinInfo read-only 1
eval sizeWin [lrange [getGeometry] 2 end]
}
proc odbBrowseRight {} {
set curPos [getPos]
set curLineStart [lineStart $curPos]
set curLineEnd [nextLineStart $curPos]
if {[regexp {^( *).+◊tabl◊\t+∞(.+)∞} [getText $curLineStart $curLineEnd] junk ind addr]} {
set nextIndString [odbGetNextIndString $ind]
set nextLineText [getText [nextLineStart $curLineStart] [nextLineStart [nextLineStart $curLineStart]]]
if {![regexp "^$nextIndString" $nextLineText junk]} {
set cells [frontierDoAlphaScript "Alpha.getCellData(@$addr)"]
odbBrowserAddCells $curLineEnd $cells [odbGetIndLevel $nextIndString]
}
}
select $curLineStart $curLineEnd
}
proc odbBrowseLeft {} {
set curPos [getPos]
set curLineStart [lineStart $curPos]
set curLineEnd [nextLineStart $curPos]
if {[regexp {^( *).+∞(.+)∞} [getText $curLineStart $curLineEnd] junk ind elems]} {
set pos [nextLineStart $curLineStart]
set start $pos
set nextIndString [odbGetNextIndString $ind]
while {[regexp "^$nextIndString" [getText $pos [nextLineStart $pos]] junk]} {
set pos [nextLineStart $pos]
}
setWinInfo read-only 0
deleteText $start $pos
setWinInfo dirty 0
setWinInfo read-only 1
}
select $curLineStart $curLineEnd
}
proc odbBrowseEditObj {} {
set curPos [getPos]
set curLineStart [lineStart $curPos]
set curLineEnd [nextLineStart $curPos]
if {[regexp {^.+∞(.+)∞} [getText $curLineStart $curLineEnd] junk addr]} {
frontierDoAlphaScript "Alpha.editCell(@$addr)"
}
}
proc odbBrowse {{addr root}} {
if {$addr == ""} {
return
}
global odbBrowserTypeOffset
global odbBrowserTabLength
set cell [frontierDoAlphaScript "Alpha.getCellData(@$addr, false)"]
set wtitle "* Frontier “[lindex [lindex $cell 0] 2]” *"
if {[lsearch [winNames] $wtitle] >= 0} {
bringToFront $wtitle
} else {
new -n $wtitle -g 4 42 449 300
setWinInfo dirty 0
newMode Odb
odbBrowserAddCells 0 $cell 0
select 0 [nextLineStart 0]
odbBrowseRight
}
}
bind '\r' odbBrowseEditObj Odb
bind enter odbBrowseEditObj Odb
bind down odbBrowseDown Odb
bind down <c> odbBrowseCmdDown Odb
bind down <co> {odbBrowseCmdDown 1} Odb
bind up odbBrowseUp Odb
bind up <c> odbBrowseCmdUp Odb
bind up <co> {odbBrowseCmdUp 1} Odb
bind right odbBrowseRight Odb
bind left odbBrowseLeft Odb
catch {frontierBuildScriptMenu}